﻿Type=Class
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@

Sub Class_Globals
	Public bAMapAppExist As Boolean
	'lat 纬度
	'lon 经度
	'poiname POI 名称
	'dev 是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密),默认0即可
	Type MapPoint(lat As Double,lon As Double,poiname As String,dev As Int)
	Private mWebApiAddr As String="http://m.amap.com/?"
End Sub

'根据高德地图uri文档编写，实现了简单的调用功能
Public Sub Initialize
	bAMapAppExist=AMapInstalled
End Sub

'Type wvUrl(Url As String,allowZoom As Boolean,title As String) '自己加到合适的地方，用来传递参数的
Private Sub CallUrlOutter(wv As wvUrl)
	'这里应该自己实现一个调用webview的代码，本项目中会通过comm调用一个通用webview界面
	Log("callUrlOutter:"&wv.Url)
	comm.startWV(wv)
End Sub
'检查高德地图App是否已经安装在本机，如果没有安装的话，只能调用网页版
Public Sub AMapInstalled As Boolean
	'高德地图的包名:com.autonavi.minimap
	Dim amappkg As String="com.autonavi.minimap"
	Dim pi As PackageManager
	Dim lst As List=pi.GetInstalledPackages
	Dim ts As String
	For i=0 To lst.Size-1
		ts=lst.Get(i)
		If ts.ToLowerCase.Contains(amappkg) Then Return True
	Next
	Return False
End Sub
Public Sub BiaoZhuSingle(lat As String,lon As String,name As String)
	Dim amap As clsAMapUri
	amap.Initialize
	Dim lst As List
	lst.Initialize
	Dim tp As MapPoint
	tp.Initialize
	tp.lat=lat
	tp.lon=lon
	tp.poiname=name
	lst.Add(tp)
	BiaoZhu(lst,comm.S_APPNAME,False)
End Sub
'调用标注功能
'MapPoint类型的list 数量最多只能显示10个,如果是多点标注 其中第一个点应该是自己的坐标
'多点标注，只有web api支持 
'坐标点可以这里采集：http://lbs.amap.com/console/show/picker
Public Sub BiaoZhu(mplst As List,appname As String,useApp As Boolean)
	If mplst.IsInitialized=False Or mplst.Size=0 Then Return
	If bAMapAppExist=False Then useApp=False
	Dim mp As MapPoint,uri As String
	If useApp Then
		mp=mplst.Get(0)
		uri=	$"androidamap://viewMap?sourceApplication=${appname}&poiname=${mp.poiname}&lat=${mp.lat}&lon=${mp.lon}&dev=${mp.dev}"$
		CallAMapAppWithUri(uri)
	Else
		For i=0 To mplst.Size-1
			If i=9 Then Exit '最多只支持10个点
			Dim mp1 As MapPoint
			mp1=mplst.Get(i)
			If mp1.poiname.Length>0 Then
				uri=uri&"|"&mp1.lon&","&mp1.lat&","&mp1.poiname
			Else
				uri=uri&"|"&mp1.lon&","&mp1.lat
			End If
		Next
		uri=uri.SubString(1)
		uri="mk="&uri
		Dim wv As wvUrl
		wv.Initialize
		wv.Url=mWebApiAddr&uri
		wv.title=appname
		wv.allowZoom=False
		CallUrlOutter(wv)
	End If
	
End Sub
public Sub CallAMapAppWithUri(uri As String) As Boolean
	Dim i As Intent
	i.Initialize(i.ACTION_VIEW,uri)
	i.AddCategory("android.intent.category.DEFAULT")
	i.SetComponent("com.autonavi.minimap")
	Try
		StartActivity(i)	
	Catch
		Log(LastException.Message)
		Return False
	End Try
	Return True
End Sub